package com.ddwl.wallet.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.wallet.DeductedSubsidyBo;
import com.ddwl.schema.bo.wallet.ProvideSubsidyBo;
import com.ddwl.schema.bo.wallet.UserSubsidyFlowQueryBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.wallet.UserSubsidyFlowVo;
import com.ddwl.schema.vo.wallet.UserSubsidyVo;
import com.ddwl.wallet.service.UserSubsidyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * 类CouponController.java的实现描述：购物卷接口
 *
 * @author zach
 * @Date :2020-07-29 16:28.
 */

@Api(tags = "购物津贴接口")
@RequestMapping("subsidy")
@RestController
public class SubsidyController extends BaseController {

    @Resource
    public UserSubsidyService userSubsidyService;

    @ApiOperation(value = "查询用户津贴流水")
    @PostMapping("/page")
    @Auth(product = {BaseEnum.ProductEnum.MALL, BaseEnum.ProductEnum.FENXIAO, BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo<PageVo<UserSubsidyFlowVo>> queryUserWithdrawChannel(@RequestBody PageBo<UserSubsidyFlowQueryBo> bo) {
        if (bo.getParam() == null) {
            bo.setParam(new UserSubsidyFlowQueryBo());
        }
        bo.getParam().setUserId(getUserId());
        return RestVo.ok(userSubsidyService.queryPage(bo));
    }

    @ApiOperation(value = "发放送津贴")
    @PostMapping("/provideSubsidy")
    RestVo provideSubsidy(@RequestBody ProvideSubsidyBo bo) {
        userSubsidyService.provideSubsidy(bo);
        return RestVo.ok();
    }


    //@PostMapping("/cre")
    @ApiOperation(value = "创建新人购物津贴")
    public RestVo<BigDecimal> creCoupon() {
        return RestVo.ok(userSubsidyService.createCoupon(getDk()));
    }

    @PostMapping("/take")
    @ApiOperation(value = "领取新人购物津贴")
    @Auth(product = {BaseEnum.ProductEnum.MALL, BaseEnum.ProductEnum.FENXIAO, BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo<BigDecimal> take() {
        return RestVo.ok(userSubsidyService.take(getUserId()));
    }

    @GetMapping("/{userId}/get")
    @ApiOperation(value = "获取用户购物津贴")
    @Auth(product = BaseEnum.ProductEnum.API)
    public RestVo<UserSubsidyVo> get(@PathVariable String userId, String product) {
        return RestVo.ok(userSubsidyService.getUserCouponVo(userId, product));
    }

    @GetMapping("/get")
    @ApiOperation(value = "用户查询购物津贴余额")
    @Auth(product = {BaseEnum.ProductEnum.MALL, BaseEnum.ProductEnum.FENXIAO, BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo<UserSubsidyVo> get() {
        return RestVo.ok(userSubsidyService.getUserCouponVo(getUserId()));
    }


    @GetMapping("/isTake")
    @ApiOperation(value = "查询用户是否领用过新人津贴")
    @Auth(product = {BaseEnum.ProductEnum.MALL, BaseEnum.ProductEnum.FENXIAO, BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo<Boolean> isTake() {
        return RestVo.ok(userSubsidyService.isTake(getUserId()));
    }


    @PostMapping("/deductedSubsidy")
    @ApiOperation(value = "订单抵扣津贴")
    @Auth(product = BaseEnum.ProductEnum.API)
    public RestVo deductedSubsidy(@RequestBody DeductedSubsidyBo bo) {
        userSubsidyService.deductedSubsidy(bo);
        return RestVo.ok();
    }

}
